<?php //strip
/**
 * Prohledávání položek obchodu
 * 
 * @author Ondrej Donek <ondrejd@gmail.com>
 * @version 0.1
 */
class odEshopSearchformWidget extends WP_Widget
{
  
  /**
   * Constructor.
   * 
   * @return void
   */
  function odEshopSearchformWidget() 
  {
    // Widget base properties
    $id_base = strtolower('odEshopSearchformWidget') . '-widget';
    $name = 'Vyhledávání DVD';
    $description = 'Prohledávání položek obchodu';
    
		// Widget options
		$widget_options = array('classname'   => 'odEshopSearchformWidget', 
														'description' => $description);
		// Widget control options
		$control_options = array('width'   => 200, 
														 'height'  => 350, 
														 'id_base' => $id_base);
		
		// Create the widget
		parent::WP_Widget($id_base, $name, $widget_options, $control_options);
  }
  
  /**
   * Create widget.
   * 
   * @param array $args
   * @param array $instance
   * @return void
   */
  function widget($args, $instance) 
  {
		extract($args);
	
		// User-selected settings
		$title = apply_filters('widget_title', $instance['title']);
		$desc = $instance['description'];
	
		// Before widget (defined by theme)
		echo $before_widget;
		
		// Render our widget
		global $od_eshop_plugin;
?>
<form action="<?php echo $od_eshop_plugin->get_search_results_page_url();?>" method="post">
    <div class="vyhledavani">
	    <h1><?php echo $title;?></h1>
	    <h2><?php echo $desc;?></h2>
	    <label for="nazev">Název filmu:</label>
	    <input type="text" name="nazev" id="nazev" value="" />
		<label for="nazev_orig">Orig. název:</label>
		<input type="text" name="nazev_orig" id="nazev_orig" value="" />
	    <label for="reziser">Režisér:</label>
	    <input type="text" name="reziser" id="reziser" value="" />
	    <label for="nazev">Herec / série:</label>
	    <input type="text" name="herec" id="herec" value="" />
	    <label for="shopno">Číslo DVD</label>
	    <input type="text" name="shopno" id="shopno" value="" />
	    <label for="kategorie">Kategorie:</label>
			<?php echo $od_eshop_plugin->render_genre_categories_select('kategorie', '- všechny kategorie -');?>
	    <input type="submit" name="" value="Vyhledat" class="odeslat" />
			<p><?php echo $od_eshop_plugin->get_eshop_items_count(true);?></p>
			<p>
			<b>Zobrazte si kompletní nabídku DVD:</b>
			<br />
			<a href="<?php echo $od_eshop_plugin->get_main_page_url();?>">Vstupte do katalogu</a>
			</p>
    </div>
	<script type="text/javascript">
	/* <![CDATA[ */
	window.addEvent('domready', function() {
		new Autocompleter.Ajax.Json(
		    'nazev', 
		    <?php echo "'" . get_option('home') . "/autocomplete-data.php'";?>, {
			'postVar': 'q'
		});
		new Autocompleter.Ajax.Json(
		    'nazev_orig', 
		    <?php echo "'" . get_option('home') . "/autocomplete-data1.php'";?>, {
			'postVar': 'q'
		});
	});
	/* ]]> */
	</script>
</form>
<?php
		
		// After widget (defined by theme)
		echo $after_widget;
  }
  
  /**
   * Updates and returns plugin instance.
   * 
   * @param array $new_instance
   * @param array $old_isntance
   * @return array
   */
  function update($new_instance, $old_instance) 
  {
		$instance = $old_instance;
	
		// Strip tags (if needed) and update the widget settings
		$instance['title'] = $new_instance['title'];
	
		return $instance;
  }
  
  /**
   * Renders widget form for the WordPress admin
   * 
   * @param array $instance
   * @return void
   */
  function form($instance) 
  {
		// Use default widget settings.
		$defaults = array('title'        => 'Vyhledávání DVD', 
							'description'  => 'Prohledávání položek obchodu');
		$instance = wp_parse_args((array) $instance, $defaults); 
?>
	<p>
	  <label for="<?php echo $this->get_field_id('title');?>">Title:</label>
	  <input id="<?php echo $this->get_field_id('title');?>" name="<?php echo $this->get_field_name('title');?>" value="<?php echo $instance['title'];?>" style="width:100%;"/>
	</p>
	<p>
	  <label for="<?php echo $this->get_field_id('description');?>">Description:</label>
	  <textarea id="<?php echo $this->get_field_id('description');?>" name="<?php echo $this->get_field_name('description');?>"><?php echo $instance['description'];?></textarea>
	</p>
<?php
  }
  
}
